package com.lulu.lulurpc.serializer;

import com.lulu.lulurpc.spi.SpiLoader;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author wlc
 * @version 1.0
 */
@Slf4j
public class SerializerFactory {

    //饿汉式加载
//    static {
//        SpiLoader.load(Serializer.class);
//    }

    private static volatile Map instance;


    /**
     * 默认序列化器
     */
    private static final Serializer DEFAULT_SERIALIZER = new JdkSerializer();

    /**
     * 获取实例
     *
     * @param key
     * @return
     */
    public static Serializer getInstance(String key) {
        if(instance==null){
            synchronized (SerializerFactory.class){
                if(instance==null){
                    instance=SpiLoader.load(Serializer.class);;
                }
            }
        }
        return SpiLoader.getInstance(Serializer.class, key);
    }
}
